package uk.ac.ebi.bioinvindex.model.impl.term;

import uk.ac.ebi.bioinvindex.model.impl.MaterialImpl;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 * User: Nataliya Sklyar (nsklyar@ebi.ac.uk)
 * Date: Jul 12, 2007
 */
@Entity
@DiscriminatorValue( "CharacteristicValue" )
public class CharacteristicValueImpl extends PropertyValueImpl<CharacteristicImpl> {

	private MaterialImpl material;

	protected CharacteristicValueImpl() {
	}

	public CharacteristicValueImpl(CharacteristicImpl type) {
		super(type);
	}

	public CharacteristicValueImpl(String value, CharacteristicImpl type) {
		super(type);
		this.setValue ( value );
	}

	@ManyToOne( targetEntity = uk.ac.ebi.bioinvindex.model.impl.MaterialImpl.class)
	@JoinColumn (name = "MATERIAL_ID", nullable = true )
	public MaterialImpl getMaterial() {
		return this.material;
	}

	public void setMaterial(MaterialImpl material) {
		this.material = material;

		//ToDo: maybe add this char.Value to Material
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		if (!super.equals(o)) return false;

		CharacteristicValueImpl that = (CharacteristicValueImpl) o;

		if (material != null ? !material.equals(that.material) : that.material != null) return false;

		return true;
	}

	public int hashCode() {
		int result = super.hashCode();
		result = 31 * result + (material != null ? material.hashCode() : 0);
		return result;
	}

	
	

}
